
$(function () {
    $('#save-trade-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        // var tr = self.parent().parent();

        var dialog = $('#trade-dialog');

        var type_id = document.getElementsByName("type_id")[0].value;
        var phone = $("input[name='phone']").val();
        var num = $("input[name='num']").val();
        // var submitType = self.attr("data-type");
        var trade_id = self.attr('data-id');

        console.log(trade_id);

        zlajax.post({
            'url':'/orders/trade_buy_sell/',
            'data':{
                'phone': phone,
                'trade_id': trade_id,
                'wallet_type': type_id,
                'num': num,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});


$(function () {
    $(".trade-sell-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#trade-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var savebtn = dialog.find("#save-trade-btn");

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});



$(function () {
    $('.trade-confirm-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要完成订单吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/orders/cms_seller_confirm/',
                    'data':{
                        'trade_id':order_id
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                            zlalert.alertError(data['message']);
                        }
                    }
                })
            }
        })
    })
});




$(function () {
    $('.penalty-buy-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要惩罚买家吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/orders/trade_penalty/',
                    'data':{
                        'trade_id':order_id,
                        'penalty_status':1,
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                             const timer =setInterval(() => {
                                zlalert.alertError(data['message']);
                                clearInterval(timer);

                            }, 100);
                        }
                    }
                })
            }
        })
    })
});



$(function () {
    $('.penalty-sell-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要惩罚卖家吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/orders/trade_penalty/',
                    'data':{
                        'trade_id':order_id,
                        'penalty_status':2,
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                             const timer =setInterval(() => {
                                zlalert.alertError(data['message']);
                                clearInterval(timer);

                            }, 100);
                        }
                    }
                })
            }
        })
    })
});


$(function () {
    $('.del-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var order_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要取消订单吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/orders/cms_del_order/',
                    'data':{
                        'trade_id':order_id
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                            const timer =setInterval(() => {
                                zlalert.alertError(data['message']);
                                clearInterval(timer);

                            }, 100);
                        }
                    }
                })
            }
        })
    })
});


